local nirao = fk.CreateSkill{
  name = "xiaobai__nirao",
}

Fk:loadTranslationTable{
  ["xiaobai__nirao"] = "逆饶",
  [":xiaobai__nirao"] = "每名角色的回合限一次，一名角色不因使用或打出失去牌后，若其已横置，你可以令其摸两张牌，然后若其手牌数大于体力上限，"..
  "重置其武将牌。",
  ["#xiaobai__nirao-invoke"] = "逆饶：是否令 %dest 摸两张牌？",

  ["$xiaobai__nirao1"] = "君当自囚诣狱，显求受罪，或可逆见优饶。",
  ["$xiaobai__nirao2"] = "琅琊王好善慕名，不杀君明矣。",
}


nirao:addEffect(fk.AfterCardsMove, {
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and player:usedSkillTimes(nirao.name, Player.HistoryTurn) == 0 then
      for _, move in ipairs(data) do
        if move.from and move.from.chained and
          not table.contains({fk.ReasonUse, fk.ReasonResponse}, move.moveReason) then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
              return true
            end
          end
        end
      end
    end
  end,
  on_trigger = function(self, event, target, player, data)
    local room = player.room
    local targets = {}
    for _, move in ipairs(data) do
      if move.from and move.from.chained and
        not table.contains({fk.ReasonUse, fk.ReasonResponse}, move.moveReason) then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
            table.insertIfNeed(targets, move.from)
          end
        end
      end
    end
    room:sortByAction(targets)
    for _, id in ipairs(targets) do
      if player:usedSkillTimes(nirao.name, Player.HistoryTurn) > 0 or not player:hasSkill(self) then break end
      local p = id
      if not p.dead then
        self:doCost(event, p, player, data)
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(player, {
      skill_name = nirao.name,
      prompt = "#xiaobai__nirao-invoke::"..target.id})
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:doIndicate(player, {target})
    target:drawCards(2, nirao.name)
    if target:getHandcardNum() > target.maxHp and not target.dead and target.chained then
      target:setChainState(false)
    end
  end,
})

return nirao